package com.heihei.controller.res;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heihei.common.page.Query;
import com.heihei.common.response.ResponseVO;
import com.heihei.service.res.ResResourceService;
import com.heihei.vo.res.ResResourceQueryParamVO;
import com.heihei.vo.res.ResResourceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  资源列表信息 Controller
 * </p>
 *
 * @author duanhengfei
 * @since 2021-11-23
 */
@Api(tags = "资源列表信息 Controller")
@RestController
@RequestMapping("/res/resource")
public class ResResourceController {
    @Resource
    private ResResourceService resResourceService;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public ResponseVO<String> add(@RequestBody ResResourceVO paramVo) {
        return this.resResourceService.add(paramVo);
    }

    @ApiOperation(value = "修改")
    @PatchMapping("/update")
    public ResponseVO<Boolean> update(@RequestBody ResResourceVO paramVo) {
        return this.resResourceService.myUpdateById(paramVo);
    }

    @ApiOperation(value = "删除")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "path", dataType = "String")
    @DeleteMapping("/delete/{id}")
    public ResponseVO<Boolean> delete(@PathVariable String id) {
        return this.resResourceService.deleteByIdLogic(id);
    }

    @ApiOperation(value = "批量删除（直接传入一个id数组）")
    @DeleteMapping("/delete-batch")
    public ResponseVO<Boolean> deleteBatch(@RequestBody List<String> idList) {
        return this.resResourceService.deleteBatch(idList);
    }

    @ApiOperation(value = "列表查询")
    @GetMapping("/pageList")
    public ResponseVO<IPage<ResResourceVO>> list(ResResourceQueryParamVO paramVo, Query query) {
        return this.resResourceService.myPageList(paramVo, query);
    }

    @ApiOperation(value = "详情")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, paramType = "path")
    @GetMapping("/detail/{id}")
    public ResponseVO<ResResourceVO> detail(@PathVariable String id) {
        return this.resResourceService.myGetById(id);
    }
}
